Closures in JavaScript are functions that "remember" the variables from their outer scope even after the outer function has finished executing. A closure allows an inner function to access and manipulate variables from an outer function even after the outer function has returned.
outerFunction
returns innerFunction
, which still has access to outerVariable
even after outerFunction
has executed.closureExample("World")
is called, it retains the reference to outerVariable
("Hello").Would you like an example of closures in a real-world scenario? 🚀